<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="/includes.jsp"%>

<h1 class="layout">Time Report</h1>

<table class="layout">
    <tr><th class="layout">Root Node:</th><td class="layout"><beans:write name="timeReportDTO" property="rootPath"/></td></tr>
    <tr><th class="layout">Start Date:</th><td class="layout"><beans:write name="timeReportDTO" property="startDate" format="yyyy-MM-dd"/></td></tr>
    <tr><th class="layout">Stop Date:</th><td class="layout"><beans:write name="timeReportDTO" property="stopDate" format="yyyy-MM-dd"/></td></tr>
</table>

<jsp:useBean id="durationHours" class="java.util.Date"/>
<jsp:useBean id="durationMins" class="java.util.Date"/>

<logic:iterate name="timeReportDTO" property="summaries" id="summary">
    <h2><beans:write name="summary" property="name"/> Summary</h2>
    <table class="styled" cellspacing="0">
        <tr>
            <th class="styled"><beans:write name="summary" property="name"/></th>
            <logic:iterate name="timeReportDTO" property="colNames" id="name">
                <th class="styled"><beans:write name="name"/></th>
            </logic:iterate>
        </tr>
        <logic:iterate name="summary" property="rows" id="row">
            <tr>
                <td class="styled"><beans:write name="row" property="name"/></td>
                <logic:iterate name="row" property="longPercents" id="duration">
                    <jsp:setProperty name="durationHours" property="time" value="<%=((TimeSummaryTable.Row.LongPercent)duration).getLong()/3600000L%>"/>
                    <jsp:setProperty name="durationMins" property="time" value="<%=(((TimeSummaryTable.Row.LongPercent)duration).getLong()/60000L)%60L%>"/>
                    <td class="styled">
                        <logic:notEqual name="duration" property="long" value="0">
                            <div class="histogram" style="width: <beans:write name="duration" property="percent"/>%">
                                <beans:write name="durationHours" property="time" format="##"/>h:<beans:write name="durationMins" property="time" format="00"/>m
                            </div>
                        </logic:notEqual>
                        <logic:equal name="duration" property="long" value="0">&nbsp;</logic:equal>
                    </td>
                </logic:iterate>
            </tr>
        </logic:iterate>
    </table>
</logic:iterate>

<logic:notEmpty name="timeReportDTO" property="timeEntries">
    <h2>Entries</h2>
    <table class="styled" cellspacing="0">
        <tr>
            <th class="styled">Person</th>
            <th class="styled">Task/State</th>
            <th class="styled">Date/Duration</th>
            <th class="styled">Description</th>
        </tr>
        <logic:iterate name="timeReportDTO" property="timeEntries" id="entry">
            <tr>
                <td class="styled"><beans:write name="entry" property="person"/></td>
                <td class="styled"><beans:write name="entry" property="task"/></br><beans:write name="entry" property="state"/></td>                
                <beans:define id="duration" name="entry" property="duration"/>
                <jsp:setProperty name="durationHours" property="time" value="<%=((Long)duration).longValue()/3600000L%>"/>
                <jsp:setProperty name="durationMins" property="time" value="<%=(((Long)duration).longValue()/60000L)%60L%>"/>
                <td class="styled"><beans:write name="entry" property="date" format="yyyy-MM-dd HH:mm"/></br><beans:write name="durationHours" property="time" format="##"/>h:<beans:write name="durationMins" property="time" format="00"/>m</td>
                <td class="styled"><velocityme:markup><beans:write name="entry" property="description"/></velocityme:markup></td>
            </tr>
        </logic:iterate>
    </table>
</logic:notEmpty>

<div class="buttons">
    <em><small>Report created by Velocityme on <beans:write name="timeReportDTO" property="reportDate" format="yyyy-MM-dd HH:mm:ss"/></small></em>
</div>
